package com.gxa.hualian.dao.impl;

import com.gxa.hualian.dao.CouponDao;
import com.gxa.hualian.entity.Coupon;

import java.util.List;

public class CouponImpl extends BaseDaoImpl<Coupon> implements CouponDao {
    @Override
    public Integer insert(Coupon coupon) throws Exception {
        return  super.insert(coupon);

    }

    @Override
    public List<Coupon> selectAll() throws Exception {
        return super.selectAll(Coupon.class);
    }

    @Override
    public List<Coupon> selectByPhone(String phone) throws Exception {
        return super.selectByName("phone",phone,Coupon.class);
    }

    @Override
    public Coupon selectById(Integer id) throws Exception {
        return  super.selectById(id,Coupon.class);

    }

    @Override
    public Boolean deleteById(Integer id) throws Exception {
        return super.deleteByName("id",id,Coupon.class);
    }

    @Override
    public Integer update(Coupon coupon) throws Exception {
        return super.update("id",coupon.getId(),coupon);
    }

    @Override
    public List<Coupon> selectByPage(Integer page, Integer limit) throws Exception {
        return  super.selectByPage(page,limit,Coupon.class);
    }

    @Override
    public List<Coupon> selectLikeName(Object value) throws Exception {
        return super.selectLikeName(value,Coupon.class);
    }

    @Override
    public List<Coupon> userNotGetCpnList(String phone) throws Exception {
        String querString="select c.*,g.id as gid,g.phone from tb_coupon c \n" +
                "left join `tb_get` g on c.id=g.id and phone="+phone+" where g.id is null\n" +
                "and inUsed=1 and collectExp> NOW() ORDER BY c.id desc";
        List<Coupon> coupons = super.selectByQuery(querString, Coupon.class, phone);
        return coupons;
    }

    @Override
    public List<Coupon> userGetCpnList(String phone)throws Exception{
        String querString="select c.*,g.id as gid,g.phone from tb_coupon c \n" +
                "left join `tb_get` g on c.id=g.id and phone="+phone+" where g.id is not null\n" +
                "and inUsed=1 and collectExp> NOW() ORDER BY c.id desc";
        List<Coupon> coupons = super.selectByQuery(querString, Coupon.class, phone);
        return coupons;
    }

    @Override
    public List<Coupon> overExpire(String phone) throws Exception {
        String querString="select c.*,g.id as gid,g.phone from tb_coupon c \n" +
                "left join `tb_get` g on c.id=g.id and phone="+phone+" \n" +
                "where usedExp < NOW() or  collectExp< NOW() ORDER BY c.id desc";
        List<Coupon> coupons = super.selectByQuery(querString, Coupon.class, phone);
        return coupons;
    }

    @Override
    public List selectByQuery(String queryString, Class clazz, Object... args) {
        return null;
    }
}
